#include <stdio.h>
#include <avr/io.h>
#include <util/delay.h>
#include "uart.h"

#define LED_DDR  DDRD
#define LED_PORT PORTD
#define LED_PIN  PIND
#define LED_BIT  PD6

#define SET_BIT(REG, BIT) do {REG |= _BV(BIT);}while(0)
#define CLR_BIT(REG, BIT) do {REG &= ~_BV(BIT);}while(0)

static void activate_led()
{
	SET_BIT(LED_DDR, LED_BIT);
}
static void led_on()
{
	SET_BIT(LED_PORT, LED_BIT);
}
static void led_off()
{
	CLR_BIT(LED_PORT, LED_BIT);
}


int main(void)
{
	char s[100];
	activate_led();
	uart_init();
	_delay_ms(5000);
	led_on();
	_delay_ms(5000);
	printf("AT+BTSCAN\r");
	led_off();
	scanf("%s", s);
	_delay_ms(5000);
	if (s[0] == 'O' && s[1] == 'K') {
		led_on();
	}
	for(;;)
		;
}
